/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

//import * as vscode from 'vscode';

import TypeScriptServiceClientHost from './typeScriptServiceClientHost';
import { Command } from './utils/commandManager';
import { Lazy } from './utils/lazy';


export class ReloadTypeScriptProjectsCommand implements Command {
	public readonly id = 'typescript.reloadProjects';

	public constructor(
		private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>
	) { }

	public execute() {
		this.lazyClientHost.value.reloadProjects();
	}
}

export class ReloadJavaScriptProjectsCommand implements Command {
	public readonly id = 'javascript.reloadProjects';

	public constructor(
		private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>
	) { }

	public execute() {
		this.lazyClientHost.value.reloadProjects();
	}
}

// export class SelectTypeScriptVersionCommand implements Command {
// 	public readonly id = 'typescript.selectTypeScriptVersion';

// 	public constructor(
// 		private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>
// 	) { }

// 	public execute() {
// 		this.lazyClientHost.value.serviceClient.onVersionStatusClicked();
// 	}
// }

// export class OpenTsServerLogCommand implements Command {
// 	public readonly id = 'typescript.openTsServerLog';

// 	public constructor(
// 		private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>
// 	) { }

// 	public execute() {
// 		this.lazyClientHost.value.serviceClient.openTsServerLogFile();
// 	}
// }

// export class RestartTsServerCommand implements Command {
// 	public readonly id = 'typescript.restartTsServer';

// 	public constructor(
// 		private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>
// 	) { }

// 	public execute() {
// 		this.lazyClientHost.value.serviceClient.restartTsServer();
// 	}
// }

// export class TypeScriptGoToProjectConfigCommand implements Command {
// 	public readonly id = 'typescript.goToProjectConfig';

// 	public constructor(
// 		private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>,
// 		private readonly vscode: any
// 	) { }

// 	public execute() {
// 		const editor = this.vscode.window.activeTextEditor;
// 		if (editor) {
// 			goToProjectConfig(this.lazyClientHost.value, true, editor.document.uri, this.vscode);
// 		}
// 	}
// }

// export class JavaScriptGoToProjectConfigCommand implements Command {
// 	public readonly id = 'javascript.goToProjectConfig';

// 	public constructor(
// 		private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>,
// 		private readonly vscode: any
// 	) { }

// 	public execute() {
// 		const editor = this.vscode.window.activeTextEditor;
// 		if (editor) {
// 			goToProjectConfig(this.lazyClientHost.value, false, editor.document.uri, this.vscode);
// 		}
// 	}
// }

// async function goToProjectConfig(
// 	clientHost: TypeScriptServiceClientHost,
// 	isTypeScriptProject: boolean,
// 	resource: any,
// 	vscode: any
// ): Promise<void> {
// 	const client = clientHost.serviceClient;
// 	const rootPath = client.getWorkspaceRootForResource(resource);
// 	if (!rootPath) {
// 		vscode.window.showInformationMessage(
// 			localize(
// 				'typescript.projectConfigNoWorkspace',
// 				'Please open a folder in VS Code to use a TypeScript or JavaScript project'));
// 		return;
// 	}

// 	const file = client.normalizePath(resource);
// 	// TSServer errors when 'projectInfo' is invoked on a non js/ts file
// 	if (!file || !clientHost.handles(file)) {
// 		vscode.window.showWarningMessage(
// 			localize(
// 				'typescript.projectConfigUnsupportedFile',
// 				'Could not determine TypeScript or JavaScript project. Unsupported file type'));
// 		return;
// 	}

// 	let res: any | undefined = undefined;
// 	try {
// 		res = await client.execute('projectInfo', { file, needFileNameList: false });
// 	} catch {
// 		// noop
// 	}
// 	if (!res || !res.body) {
// 		vscode.window.showWarningMessage(localize('typescript.projectConfigCouldNotGetInfo', 'Could not determine TypeScript or JavaScript project'));
// 		return;
// 	}

// 	const { configFileName } = res.body;
// 	if (configFileName && !isImplicitProjectConfigFile(configFileName)) {
// 		const doc = await vscode.workspace.openTextDocument(configFileName);
// 		vscode.window.showTextDocument(doc, vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined);
// 		return;
// 	}

// 	enum ProjectConfigAction {
// 		None,
// 		CreateConfig,
// 		LearnMore
// 	}

// 	interface ProjectConfigMessageItem extends vscode.MessageItem {
// 		id: ProjectConfigAction;
// 	}

// 	const selected = await this.vscode.window.showInformationMessage<ProjectConfigMessageItem>(
// 		(isTypeScriptProject
// 			? localize('typescript.noTypeScriptProjectConfig', 'File is not part of a TypeScript project')
// 			: localize('typescript.noJavaScriptProjectConfig', 'File is not part of a JavaScript project')
// 		), {
// 			title: isTypeScriptProject
// 				? localize('typescript.configureTsconfigQuickPick', 'Configure tsconfig.json')
// 				: localize('typescript.configureJsconfigQuickPick', 'Configure jsconfig.json'),
// 			id: ProjectConfigAction.CreateConfig
// 		}, {
// 			title: localize('typescript.projectConfigLearnMore', 'Learn More'),
// 			id: ProjectConfigAction.LearnMore
// 		});

// 	switch (selected && selected.id) {
// 		case ProjectConfigAction.CreateConfig:
// 			openOrCreateConfigFile(isTypeScriptProject, rootPath, client.configuration);
// 			return;

// 		case ProjectConfigAction.LearnMore:
// 			if (isTypeScriptProject) {
// 				vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://go.microsoft.com/fwlink/?linkid=841896'));
// 			} else {
// 				vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://go.microsoft.com/fwlink/?linkid=759670'));
// 			}
// 			return;
// 	}
// }